import Vue from "vue";

import {
    Button,
    Select,
    Input,
    Form,
    FormItem,
    Dialog,
    InputNumber,
    Radio,
    RadioGroup,
    // RadioButton,
    Checkbox,
    // CheckboxButton,
    CheckboxGroup,
    Switch,
    Option,
    // OptionGroup,
    // ButtonGroup,
    Table,
    TableColumn,
    Row,
    Col,
    Menu,
    Submenu,
    MenuItem,
    MenuItemGroup,
    Progress,
    Pagination,
    Tabs,
    TabPane,
    Popover,
    Steps,
    Step,
    // Breadcrumb,
    // BreadcrumbItem,
    Tag,
    Upload,
    Dropdown,
    DropdownMenu,
    DropdownItem,
    Divider,
    Collapse,
    CollapseItem,
    drawer,
    Card,
    Loading,
    Link,
    Notification,
    Popconfirm,
    DatePicker
} from "element-ui";
Vue.use(Popconfirm);
Vue.use(Card);
Vue.use(Button);
Vue.use(Select);
Vue.use(Input);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Dialog);
Vue.use(InputNumber);
Vue.use(Radio);
Vue.use(Table);
Vue.use(RadioGroup);
Vue.use(DatePicker);
// Vue.use(RadioButton);

Vue.use(Checkbox);
// Vue.use(CheckboxButton);
Vue.use(CheckboxGroup);
Vue.use(Switch);

Vue.use(Option);
// Vue.use(OptionGroup);
// Vue.use(ButtonGroup);
// Vue.use(Table);
Vue.use(TableColumn);
Vue.use(Row);
Vue.use(Col);
Vue.use(Menu);
Vue.use(Submenu);
Vue.use(MenuItem);
Vue.use(MenuItemGroup);
Vue.use(Progress);
Vue.use(Pagination);
Vue.use(Tabs);
Vue.use(TabPane);
Vue.use(Popover);
Vue.use(Link);
Vue.use(Steps);
Vue.use(Step);
// Vue.use(Breadcrumb);
// Vue.use(BreadcrumbItem);
Vue.use(Tag);
Vue.use(Upload);

Vue.use(Dropdown);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Divider);

Vue.use(Collapse);
Vue.use(CollapseItem);
Vue.use(drawer);
Vue.use(Loading.directive);
require("./style/index.less");
Vue.prototype.$loading = Loading.service;
import { Message } from "element-ui";

const $Message = {
    success(message = "成功", duration = 1500) {
        Message({
            message: message,
            duration,
            type: "success",
        });
    },

    warning(message, duration = 1500) {
        Message({
            message: message,
            duration,
            type: "warning",
        });
    },
    info(message, duration = 1500) {
        Message({
            message: message,
            duration,
            type: "info",
        });
    },
    error(message = "错误", duration = 1500) {
        Message({
            message: message,
            duration,
            type: "error",
        });
    },
};

Vue.prototype.$msgOk = $Message.success;
Vue.prototype.$msgWarning = $Message.warning;
Vue.prototype.$msgInfo = $Message.info;
Vue.prototype.$msgError = $Message.error;
export const $message = $Message;

//定义 ui操作弹框提示
import { MessageBox } from "element-ui";

const $MessageBox = {
    msgbox(message, type = "success", title = "Message") {
        MessageBox({
            closeOnClickModal: false,
            message: message,
            cancelButtonClass: "cancelButton",
            confirmButtonClass: "confirmButton",
            type,
            iconClass: "successIcon",
            title: title,
            confirmButtonText: "OK",
        });
    },

    alert(message, options = {}) {
        const { type = "info", title = "Message", confirmButtonText = "ok", cancelButtonText = "取消", callback = null, showClose = true, showConfirmButton = true, dangerouslyUseHTMLString = false, customClass } = options;
        return new Promise((resolve) => {
            MessageBox.alert(message, title, {
                closeOnClickModal: false,
                type,
                cancelButtonText: cancelButtonText,
                confirmButtonText: confirmButtonText,
                dangerouslyUseHTMLString,
                cancelButtonClass: "cancelButton",
                confirmButtonClass: "confirmButton",
                customClass,
                callback(action) {
                    if (callback != null) {
                        callback();
                    }
                    if (action === "confirm") {
                        resolve(true);
                    } else {
                        resolve(false);
                    }
                },
                showClose,
                showConfirmButton,
            });
        });
    },

    confirm(message, options = {}) {
        const { type = "warning", title = "确定", cancelButtonText = "取消", confirmButtonText = "ok", dangerouslyUseHTMLString = false, showClose = true, customClass, showCancelButton = true } = options;
        return new Promise((resolve) => {
            MessageBox.confirm(message, title, {
                closeOnClickModal: false,
                type,
                cancelButtonText: cancelButtonText,
                confirmButtonText: confirmButtonText,
                dangerouslyUseHTMLString,
                cancelButtonClass: "cancelButton",
                confirmButtonClass: "confirmButton",
                customClass,
                showClose,
                showCancelButton,
                callback(action) {
                    if (action === "confirm") {
                        resolve(true);
                    } else {
                        resolve(false);
                    }
                },
            });
        });
    },
    prompt(message, type = "", title = "Message") {
        return new Promise((resolve) => {
            MessageBox.prompt(message, title, {
                closeOnClickModal: false,
                type,
                cancelButtonText: "cancel",
                confirmButtonText: "OK",
                cancelButtonClass: "cancelButton",
                confirmButtonClass: "confirmButton",
            })
                .then(({ value }) => {
                    resolve(value);
                })
                .catch(() => {
                    resolve(false);
                });
        });
    },
};

Vue.prototype.$msgbox = $MessageBox.msgbox;
Vue.prototype.$alert = $MessageBox.alert;
Vue.prototype.$alertError = function(message, options) {
    options = Object.assign({ type: "error", title: "错误" }, options);
    return $MessageBox.alert(message, options);
};
Vue.prototype.$confirm = $MessageBox.confirm;
Vue.prototype.$prompt = $MessageBox.prompt;

export const $messageBox = $MessageBox;
//通知
Vue.prototype.$notify = Notification;